#include<iostream>
#include<vector>

using namespace std;

struct TreeNode {
	int val;
	TreeNode *left;
	TreeNode *right;
	TreeNode() : val(0), left(nullptr), right(nullptr) {}
	TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
	TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};

class Solution {
public:
	vector<int> preorderTraversal(TreeNode* root) {
		TreeNode *p = root;
		vector<int> res;
		preorder(root, res);
		return res;
	}

	void preorder(TreeNode *p, vector<int> &res) {
		if (p == NULL)
			return;
		res.push_back(p->val);
		preorder(p->left,res);
		preorder(p->right,res);
	}
};

void main() {
	Solution s;
	TreeNode root(1),l1(2),l2(3);
	root.right = &l1;
	l1.left = &l2;
	s.preorderTraversal(&root);
}